<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>注册</title>
		<link rel="stylesheet" href="https://cdn.nbclass.com/statics/adminlte/css/bootstrap.min.css"/>
		<link rel="stylesheet" href="https://cdn.nbclass.com/statics/font-icon/css/icon.css?version=1.0"/>
		<link rel="stylesheet" href="https://cdn.nbclass.com/statics/iCheck/square/blue.css"/>
		<link rel="stylesheet" href="https://cdn.nbclass.com/statics/validate/css/validate.css"/>
		<link rel="stylesheet" th:href="@{/theme/zblog/css/login.css}"/>
	</head>
	<body>
	<div class="login-bg"></div>
	<div class="login-box">
		<div class="center">
			<a class="logo-a" href="/">
				<img src="/img/logo1.png" alt="logo" />
			</a>
		</div>
		<form id="registerForm" class="login-form">
			<div class="login-title">用户登录</div>
			<div class="form-group has-feedback">
				<input type="text" name="username" class="form-control" placeholder="帐号" max="14" min="3" require="必填项">
				<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
			</div>
			<div class="form-group has-feedback">
				<input id="password" name="password" type="password" class="form-control" placeholder="密码" require="必填项" nochinese="密码不能包括中文">
				<span class="glyphicon glyphicon-lock form-control-feedback"></span>
			</div>
			<div class="form-group has-feedback">
				<input id="confirmPassword" type="password" class="form-control" placeholder="确认密码" require="必填项" nochinese="密码不能包括中文">
				<span class="glyphicon glyphicon-lock form-control-feedback"></span>
			</div>
			<div class="row">
				<div class="col-xs-8">
				</div>
				<div class="col-xs-4">
					<button id="registerBtn" type="button" class="btn btn-primary btn-block btn-flat">注册</button>
				</div>
			</div>
		</form>
	</div>
	<script src="https://cdn.nbclass.com/statics/adminlte/libs/jquery.min.js"></script>
	<script src="https://cdn.nbclass.com/statics/adminlte/libs/bootstrap.min.js"></script>
	<script src="https://cdn.nbclass.com/statics/layer/layer.js"></script>
	<script src="https://cdn.nbclass.com/statics/iCheck/icheck.min.js"></script>
	<script src="https://cdn.nbclass.com/statics/validate/js/validate.js"></script>
	<script th:src="@{/js/core.js}" ></script>
	<script>
        $(function () {
            $('input').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' // optional
            });
        });
	</script>
	<script>
        $(function () {
            $("#registerBtn").on('click', function () {
                if (!doValidForm(registerForm)) {
                    //没有通过验证
                    return;
                }
                $.ajax({
                    type: "POST",
                    url: "/register",
                    data: $("#registerForm").serialize(),
                    dataType: "json",
                    success: function (data) {
                        if (data.status == 200) {
                            var access_token=data.data;
                            var payload = JSON.parse(window.atob(access_token.split(".")[1]));
                            Core.setCookieLong("access_token",access_token,payload.exp*1000);
                            layer.msg(data.msg, {
                                icon: 1,
                                offset: '30%',
                                time: 800
                            }, function () {
                                window.location.href = "/";
                            });
                        }else{
                            layer.msg(data.msg, {
                                icon: 2,
                                offset: '30%',
                                time: 2000
                            });
                        }
                    }
                });
            });
            $(document).keyup(function (event) {
                if (event.keyCode === 13) {
                    $("#registerBtn").click();
                }
            });
        })
	</script>

	</body>

</html>